layui.use(['form','layer','jquery','layedit','laydate'],function(){
	var form = layui.form,layer =layui.layer,
		layedit = layui.layedit, $ = layui.jquery;

	form.on('submit(save)',function (data) {
         console.log(data);
        $.ajax({
            url: "/iot/dispatch/save",
            type: "post",
			data: data.field,
            async: false,
            success: function (d) {
                if (d.code == 200) {
                    layer.alert(d.msg, function () {
                        layer.closeAll();
                        parent.location.reload();
                    });
                } else {
                    layer.msg(d.msg, {shift: 6, icon: 2});
                }
            }, error: function () {
                layer.msg('请求失败', {icon: 2});
            }
        });
         return false;
    });

    form.on('submit(edit)',function (data) {
        console.log(data);
        $.ajax({
            url: "/iot/dispatch/update",
            type: "post",
            data: data.field,
            async: false,
            success: function (d) {
                if (d.code == 200) {
                    layer.alert(d.msg, function () {
                        layer.closeAll();
                        parent.location.reload();
                    });
                } else {
                    layer.msg(d.msg, {shift: 6, icon: 2});
                }
            }, error: function () {
                layer.msg('请求失败', {icon: 2});
            }
        });
        return false;
    });
	
});
